package free.order.common;

import java.util.List;

public class Page<T> {
	
	/** count property 记录总数*/
    private int count = 0; 

    /** pageSize property 每页显示记录数*/
    private int pageSize = 2;

    /** pageCount property 总页数*/
    private int pageCount = 0; 

    /** page property 当前页数*/
    private int pageNum = 0;
    
    private List<T> items = null;
    
	public Page()
    {
        
    }
    
    public Page(int pageSize)
    {
        this.pageSize = pageSize;
    }
    
    public int getCount()
    {
        return count;
    }

    public void setCount(int count)
    {
        if (pageSize != 0)
        {
            pageCount = count / pageSize;
            if (count % pageSize != 0)
            {
                pageCount++;
            }
        }
        this.count = count;
        pageHandle();
    }
    
    private void pageHandle()
    {
        if (count == 0)
        {
            pageNum = 1;
            pageCount = 1;
            return;
        }

        //当前页大于总页数，设置为当前页为总页数

        if (pageNum > pageCount)
        {
            pageNum = pageCount;
        }       
    }

    public int getPageNum()
    {
        return pageNum;
    }

    public void setPageNum(int pageNum)
    {
        this.pageNum = pageNum;
    }

    public int getPageCount()
    {
        return pageCount;
    }

    public void setPageCount(int pageCount)
    {
        this.pageCount = pageCount;
    }

    public int getPageSize()
    {
        return pageSize;
    }

    public void setPageSize(int pageSize)
    {
        this.pageSize = pageSize;
    }
    
    public List<T> getItems() {
		return items;
	}

	public void setItems(List<T> items) {
		this.items = items;
	}
}
